Hotplug : Hotplug event management

更新时间:
2024-05-13
下载文档

Hotplug : Hotplug event management

This module provides hotplug listening service.

User can use the following code to import the Hotplug module.

var Hotplug = require('hotplug');

Support

The following shows Hotplug module APIs available for each permissions.

 User ModePrivilege Mode
Hotplug 
Hotplug.open 
hotplug.close 
hotplug.clear 

Hotplug Class

new Hotplug()

  • Returns: {Object} Returns hotplug object.

Create a hotplug event listener.

Example

var hotplug = new Hotplug();

Hotplug.open()

  • Returns: {Object} Returns hotplug object.

Same as new Hotplug(), but returns undefined with no exception.

Hotplug Object

The hotplug object inherits from EventEmitter, and the on() method can be used to add processing callbacks for different events.

hotplug.close()

Close this hotplug and reclaiming file descriptors. Due to the addition of asynchronous events, you must call this function manually when this object is no longer used.

hotplug.clear()

Clear all unreceived event information.

Example

var hotplug = Hotplug.open();
hotplug.clear();

Hotplug Events

The Hotplug class inherits from the EventEmitter class. The following events are thrown in some specific situations.

insert

This event occurs when the system has a device plugged in and correctly recognized, such as inserting a USB disk, SD/MMC card, etc.

Example

hotplug.on('insert', function(path, type) {
  // new device add
});

remove

In contrast to the 'insert' event, this event is generated when the device is unplugged.

Example

hotplug.on('remove', function(path, type) {
  // device removed
});

all

This event is generated for all hotplug.

Example

hotplug.on('all', function(isInsert, path, type) {
  if (isInsert) {
    // new device add
  } else {
    // device removed
  }
});

error

If an error occured an error event is emitted with the error information. System will automatically call hotplug.close() later.

Example

hotplug.on('error', function(error) {
  // check error information
});
文档内容是否对您有所帮助?
有帮助
没帮助